package com.dubito.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.dubito.entity.User;
import com.dubito.service.UserService;

@Controller
@RequestMapping(value="/user")
public class UserController {

	@Autowired
	private UserService userService;
	
	@RequestMapping(value="/login")
	public String login(User user,HttpServletRequest request){
		User currentUser = userService.login(user);
		if(currentUser == null){
			request.setAttribute("user", user);
			request.setAttribute("errorMsg", "用户名或密码错误！");
			return "index";
		}
		HttpSession session = request.getSession();
		session.setAttribute("currentUser", currentUser);
		return "success";
	}
}
